home *** CD-ROM | disk | FTP | other *** search
- ; File Window.Asm
- ;-------------------------------------------------------------------------
- ; Macintosh 68000 Development System -- Programming Example
- ;-------------------------------------------------------------------------
- ; The Window Sample Program issued with the MDS.
- ; Modified by Ray.A.Cameron to demonstate a Modal Dialog Box.
- ; Mon May 4, 1987 21:29:54
-
- ; This application displays a window within which you can enter and edit
- ; text. Program control is through four menus: the Apple menu, the File
- ; menu, the Edit menu, and the Font menu.
-
- ; The Apple menu has the standard desk accessories and an About feature.
-
- ; The File menu lets you quit the application.
-
- ; The Edit menu lets you cut, copy, paste, and clear the text in the window
- ; or in the desk accessories. Undo is provided for desk accesories only.
- ; Command key equivalents for undo, cut, copy, and paste are provided.
- ; Cutting and pasting between the application and the desk accessories is
- ; not supported. This requires use of the Scrap Manager.
-
- ; The Font menu lets you display a Modal Dialog Box to select a Font
- ; Name, Size and attributes.
-
- ; This program requires the use of a resource file called "Window.Rsrc"
- ; Window.Rsrc is created from "Window.R" using RMaker. As well as
- ; the two files "SetupFontMap" and "FontDialog".
-
- ;--------------------------------- Includes -------------------------------
-
- Include Traps.D ; Use System and ToolBox traps
- Include ToolEqu.D ; Use ToolBox equates
- Include QuickEqu.D ; Use QuickDraw equates
- Include SysEqu.D ; Use System equates
- Include PackMacs.Txt ; Use Package equates
-
- ;----------------------------- Use of Registers ---------------------------
-
- ; Operating System and Toolbox calls always preserve D3-D7, and A2-A4.
-
- ; Register use: A5-A7 are reserved by the system
- ; D1-D3, A0-A1 are unused
- ; D0 is used as a temp
-
- ModifyReg Equ D4 ; D4 holds modifier bits from GetNextEvent
- MenuReg Equ D5 ; D5 holds menu ID from MenuSelect,MenuKey
- MenuItemReg Equ D6 ; D6 holds item ID from MenuSelect,MenuKey
- AppleHReg Equ D7 ; D7 holds the handle to the Apple Menu
-
- TextHReg Equ A2 ; A2 is a handle to the TextEdit record
- WindowPReg Equ A3 ; A3 is a pointer to the editing window
- EditHReg Equ A4 ; A4 is a handle to the Edit menu
-
- ;--------------------------------- Equates --------------------------------
-
- ; These are equates associated with the resources
- ; for the Window example.
-
- AppleMenu Equ 1 ; First item in MENU resource
- AboutItem Equ 1 ; First item in Apple menu
-
- FileMenu Equ 2 ; Second item in MENU resource
- QuitItem Equ 1 ; First item in File menu
-
- EditMenu Equ 3 ; Third item in MENU resource
- UndoItem Equ 1 ; Items in Edit menu
- CutItem Equ 3 ; (Item 2 is a line)
- CopyItem Equ 4
- PasteItem Equ 5
- ClearItem Equ 6
-
- FontMenu Equ 4 ; Fourth item in MENU resource
- DialogItem Equ 1 ; Only item in Font menu
-
- AboutDialog Equ 1 ; About dialog is DLOG resource #1
- ButtonItem Equ 1 ; First item in DITL used by DLOG #1
- ASample Equ 1 ; Sample Window is WIND resource #1
-
- ;---------------------------------- Xdefs ---------------------------------
-
- ; Xdef all labels that are to be symbolically displayed by debugger.
-
- Xdef Start
- Xdef InitManagers
- Xdef SetupMenu
- Xdef SetupWindow
- Xdef SetupTextEdit
- Xdef Activate
- Xdef Deactivate
- Xdef Update
- Xdef KeyDown
- Xdef MouseDown
- Xdef SystemEvent
- Xdef Content
- Xdef Drag
- Xdef InMenu
- Xdef About
-
- XRef SetupFontMap ; Routines
- XRef FontDialog
-
- XRef FontMap ; Variable
-
- ;------------------------------- Main Program -----------------------------
-
- Start
-
- Bsr InitManagers ; Initialize managers
- Bsr SetupMenu ; Build menus, draw menu bar
- Bsr SetupWindow ; Draw Editing Window
- Bsr SetupTextEdit ; Initialize TextEdit
- Bsr SetupFontMap ; Initialize the FontMap
-
- EventLoop ; Main Program Loop
-
- _SystemTask ; Update Desk Accessories
- ; Procedure TEIdle (hTE:TEHandle);
- Move.l TextHReg,-(SP) ; Get handle to text record
- _TEIdle ; blink cursor etc.
-
- ; Function GetNextEvent(eventMask: Integer
- ; Var theEvent: EventRecord) : Boolean
- Clr -(SP) ; Clear space for result
- Move #$0FFF,-(SP) ; Allow 12 low events
- Pea EventRecord ; Place to return results
- _GetNextEvent ; Look for an event
- Move (SP)+,D0 ; Get result code
- Beq EventLoop ; No event... Keep waiting
- Bsr HandleEvent ; Go handle event
- Beq EventLoop ; Not Quit, keep going
- Rts ; Quit, exit to Finder
-
- ; Note: When an event handler finishes, it returns the Z flag set. If
- ; Quit was selected, it returns with the Z flag clear. An Rts is
- ; guaranteed to close all files and launch the Finder.
-
- ;------------------------------- InitManagers -----------------------------
-
- InitManagers
-
- Pea -4(A5) ; Quickdraw's global area
- _InitGraf ; Init Quickdraw
- _InitFonts ; Init Font Manager
- Move.l #$0000FFFF,D0 ; Flush all events
- _FlushEvents
- _InitWindows ; Init Window Manager
- _InitMenus ; Init Menu Manager
- Clr.l -(SP) ; No restart Procedure
- _InitDialogs ; Init Dialog Manager
- _TEInit ; Init Text Edit
- _InitCursor ; Turn on arrow cursor
- Rts
-
- ;------------------------------- SetupMenu ------------------------------
-
- SetupMenu
-
- ; The names of all the menus and the commands in the menus are stored in the
- ; resource file. The way you build a menu for an application is by reading
- ; each menu in from the resource file and then inserting it into the current
- ; menu bar. Desk accessories are read from the system resource file and
- ; added to the Apple menu.
-
- ; Apple Menu Set Up.
-
- ; Function GetMenu (menu ID:Integer): MenuHandle;
- Clr.l -(SP) ; Space for menu handle
- Move #AppleMenu,-(SP) ; Apple menu resource ID
- _GetRMenu ; Get menu handle
- Move.l (SP),AppleHReg ; Save for later comparison
- Move.l (SP),-(SP) ; Copy handle for AddResMenu
-
- ; Procedure InsertMenu (menu:MenuHandle; beforeID: Integer);
- Clr -(SP) ; Append to menu
- _InsertMenu ; Which is currently empty
-
- ; Add Desk Accessories Into Apple menu (Apple menu handle already on stack)
-
- ; Procedure AddResMenu (menu: MenuHandle; theType: ResType);
- Move.l #'DRVR',-(SP) ; Load all drivers
- _AddResMenu ; And Add to Apple menu
-
- ; File Menu Set Up
-
- ; Function GetMenu (menu ID:Integer): MenuHandle;
- Clr.l -(SP) ; Space for menu handle
- Move #FileMenu,-(SP) ; File Menu Resource ID
- _GetRMenu ; Get File menu handle
-
- ; Procedure InsertMenu (menu:MenuHandle; beforeID: Integer);
- Clr -(SP) ; Append to list
- _InsertMenu ; After Apple menu
-
- ; Edit Menu Set Up
-
- ; Function GetMenu (menu ID:Integer): MenuHandle;
- Clr.l -(SP) ; Space for menu handle
- Move #EditMenu,-(SP) ; Edit menu resource ID
- _GetRMenu ; Get handle to menu
- Move.l (SP),EditHReg ; Save for later
- ; Leave on stack for Insert
- ; Procedure InsertMenu (menu:MenuHandle; beforeID: Integer);
- Clr -(SP) ; Append to list
- _InsertMenu ; After File menu
-
- ; Font Menu Set Up
-
- ; Function GetMenu (menu ID:Integer): MenuHandle;
- Clr.l -(SP) ; Space for menu handle
- Move #FontMenu,-(SP) ; Font Menu Resource ID
- _GetRMenu ; Get File menu handle
-
- ; Procedure InsertMenu (menu:MenuHandle; beforeID: Integer);
- Clr -(SP) ; Append to list
- _InsertMenu ; After Edit menu
- _DrawMenuBar ; Display the menu bar
- Rts
-
- ;------------------------------ SetupWindow ------------------------------
-
- SetupWindow
-
- ; The window parameters are stored in our resource file. Read them from
- ; the file and draw the window, then set the port to that window. Note that
- ; the window parameters could just as easily have been set using the call
- ; NewWindow, which doesn't use the resource file.
-
- ; Function GetNewWindow (windowID: Integer; wStorage: Ptr;
- ; behind: WindowPtr) : WindowPtr;
- Clr.l -(SP) ; Space for window pointer
- Move #ASample,-(SP) ; Resource ID for window
- Pea WindowStorage(A5) ; Storage for window
- Move.l #-1,-(SP) ; Make it the top window
- _GetNewWindow ; Draw the window
- Move.l (SP),WindowPReg ; Save for later
-
- ; Procedure SetPort (gp: GrafPort) ; Pointer still on stack
- _SetPort ; Make it the current port
- Rts
-
- ;---------------------------- SetupTextEdit --------------------------
-
- SetupTextEdit
-
- ; Create a new text record for TextEdit, and define the window within which
- ; it will be displayed. Note that if the window boundaries are changed in
- ; the resource file, DestRect and ViewRect will have to be changed too.
-
- ; Procedure TENew (destRect,viewRect: Rect): TEHandle;
- Clr.l -(SP) ; Space for text handle
- Pea DestRect ; DestRect Rectangle
- Pea ViewRect ; ViewRect Rectangle
- _TENew ; New Text Record
- Move.l (SP)+,TextHReg ; Save text handle
- Rts
-
- ;------------------------- Event Handling Routines -----------------------
-
- HandleEvent
-
- ; Use the event number as an index into the Event table. These 12 events
- ; are all the things that could spontaneously happen while the program is
- ; in the main loop.
-
- Move Modify,ModifyReg ; More useful in a reg
- Move What,D0 ; Get event number
- Add D0,D0 ; *2 for table index
- Move EventTable(D0),D0 ; Point to routine offset
- Jmp EventTable(D0) ; and jump to it
-
- EventTable
-
- Dc.w NextEvent-EventTable ; Null Event (Not used)
- Dc.w MouseDown-EventTable ; Mouse Down
- Dc.w NextEvent-EventTable ; Mouse Up (Not used)
- Dc.w KeyDown-EventTable ; Key Down
- Dc.w NextEvent-EventTable ; Key Up (Not used)
- Dc.w KeyDown-EventTable ; Auto Key
- Dc.w Update-EventTable ; Update
- Dc.w NextEvent-EventTable ; Disk (Not used)
- Dc.w Activate-EventTable ; Activate
- Dc.w NextEvent-EventTable ; Abort (Not used)
- Dc.w NextEvent-EventTable ; Network (Not used)
- Dc.w NextEvent-EventTable ; I/O Driver (Not used)
-
- ;--------------------------- Event Actions ---------------------------
-
- Activate
-
- ; An activate event is posted by the system when a window needs to be
- ; activated or deactivated. The information that indicates which window
- ; needs to be updated was returned by the NextEvent call.
-
- Cmp.l Message,WindowPReg ; Was it our window?
- Bne NextEvent ; No, get next event
- Btst #activeFlag,ModifyReg ; Activate?
- Beq Deactivate ; No, go do Deactivate
-
- ; To activate our window, activate TextEdit, and disable Undo since we don't
- ; support it. Then set our window as the port since an accessory may have
- ; changed it. This activate event was generated by SelectWindow as a result
- ; of a click in the content region of our window. If the window had scroll
- ; bars, we would do ShowControl and HideControl here too.
-
- ; Procedure TEActivate (hTE: TEHandle);
- Move.l TextHReg,-(SP) ; Move Text Handle To Stack
- _TEActivate ; Activate Text
-
- ; Procedure DisableItem (menu:MenuHandle; item:Integer);
- Move.l EditHReg,-(SP) ; Get handle to the menu
- Move #UndoItem,-(SP) ; Enable 1st item (undo)
- _DisableItem
-
- SetOurPort ; used by InAppleMenu
-
- ; Procedure SetPort (gp: GraphPort) ; Set the port to us, since
- Move.l WindowPReg,-(SP) ; an accessory might have
- _SetPort ; changed it.
-
- NextEvent
-
- Moveq #0,D0 ; Say that it's not Quit
- Rts ; return to EventLoop
-
- Deactivate
-
- ; To deactivate our window, turn off TextEdit, and Enable undo for the desk
- ; accessories (which must be active instead of us).
-
- ; Procedure TEDeActivate (hTE: TEHandle)
- Move.l TextHReg,-(SP) ; Get Text Handle
- _TeDeActivate ; Un Activate Text
-
- ; Procedure EnableItem (menu:MenuHandle; item:Integer);
- Move.l EditHReg,-(SP) ; Get handle to the menu
- Move #UndoItem,-(SP) ; Enable 1st item (undo)
- _EnableItem
- Bra NextEvent ; Go get next event
-
- Update
-
- ; The window needs to be redrawn. Erase the window and then call TextEdit
- ; to redraw it.
-
- ; Procedure BeginUpdate (theWindow: WindowPtr);
- Move.l WindowPReg,-(SP) ; Get pointer to window
- _BeginUpDate ; Begin the update
-
- ; EraseRect (rUpdate: Rect);
- Pea ViewRect ; Erase visible area
- _EraseRect
-
- ; TEUpdate (rUpdate: Rect; hTE: TEHandle);
- Pea ViewRect ; Get visible area
- Move.l TextHReg,-(SP) ; and handle to text
- _TEUpdate ; then update the window
-
- ; Procedure EndUpdate (theWindow: WindowPtr);
- Move.l WindowPReg,-(SP) ; Get pointer to window
- _EndUpdate ; and end the update
- Bra NextEvent ; Go get next event
-
- KeyDown
-
- ; A key was pressed. First check to see if it was a command key. If so,
- ; go do it. Otherwise pass the key to TextEdit.
-
- Btst #CmdKey,ModifyReg ; Is command key down?
- Bne CommandDown ; If so, handle command key
-
- ; Procedure TEKey (key: CHAR; hTE: TEHandle);
- Move Message+2,-(SP) ; Get character
- Move.l TextHReg,-(SP) ; and text record
- _TEKey ; Give char to TextEdit
- Bra NextEvent ; Go get next event
-
- CommandDown
-
- ; The command key was down. Call MenuKey to find out if it was the command
- ; key equivalent for a menu command, pass the menu and item numbers to Choices.
-
- ; Function MenuKey (ch:CHAR): LongInt;
- Clr.l -(SP) ; Space for Menu and Item
- Move Message+2,-(SP) ; Get character
- _MenuKey ; See if it's a command
- Move (SP)+,MenuReg ; Save Menu
- Move (SP)+,MenuItemReg ; and Menu Item
- Bra Choices ; Go dispatch command
-
-
- ;--------------------Mouse Down Events And Their Actions----------------------
-
- MouseDown
-
- ; If the mouse button was pressed, we must determine where the click
- ; occurred before we can do anything. Call FindWindow to determine
- ; where the click was; dispatch the event according to the result.
-
- ; Function FindWindow (thePt: Point;
- ; Var whichWindow: WindowPtr): Integer;
- Clr -(SP) ; Space for result
- Move.l Point,-(SP) ; Get mouse coordinates
- Pea WWindow ; Event Window
- _FindWindow ; Who's got the click?
- Move (SP)+,D0 ; Get region number
- Add D0,D0 ; *2 for index into table
- Move WindowTable(D0),D0 ; Point to routine offset
- Jmp WindowTable(D0) ; Jump to routine
-
- WindowTable
-
- Dc.w NextEvent-WindowTable ; In Desk (Not used)
- Dc.w InMenu-WindowTable ; In Menu Bar
- Dc.w SystemEvent-WindowTable ; System Window
- Dc.w Content-WindowTable ; In Content
- Dc.w Drag-WindowTable ; In Drag
- Dc.w NextEvent-WindowTable ; In Grow (Not used)
- Dc.w NextEvent-WindowTable ; In Go Away (Not used)
-
- SystemEvent
-
- ; The mouse button was pressed in a system window. SystemClick calls the
- ; appropriate desk accessory to handle the event.
-
- ; Procedure SystemClick (theEvent: EventRecord;
- ; theWindow: WindowPtr);
- Pea EventRecord ; Get event record
- Move.l WWindow,-(SP) ; and window pointer
- _SystemClick ; Let the system do it
- Bra NextEvent ; Go get next event
-
- Content
-
- ; The click was in the content area of a window. If our window was in
- ; front, then call Quickdraw to get local coordinates, then pass the
- ; coordinates to TextEdit. We also determine whether the shift key was
- ; pressed so TextEdit can do shift-clicking. If our window wasn't in
- ; front, Move it to the front, but don't process click.
-
- Clr.l -(SP) ; clear room for result
- _FrontWindow ; get FrontWindow
- Move.l (SP)+,D0 ; Is front window pointer
- Cmp.l WindowPReg,D0 ; same as our pointer?
- Beq.s @1 ; Yes, call TextEdit
-
- ; We weren't active, select our window. This causes an activate event.
-
- ; Procedure SelectWindow (theWindow: WindowPtr);
- Move.l WWindow,-(SP) ; Window Pointer To Stack
- _SelectWindow ; Select Window
- Bra NextEvent ; and get next event
-
- @1
-
- ; We were active, pass the click (with shift) to TextEdit.
-
- ; Procedure GlobalToLocal (Var pt:Point);
- Pea Point ; Mouse Point
- _GlobalToLocal ; Global To Local
-
- ; Procedure TEClick (pt: Point; extend: Boolean; hTE: TEHandle);
- Move.l Point,-(SP) ; Mouse Point (GTL)
- Btst #shiftKey,ModifyReg ; Is shift key down?
- Sne D0 ; True if shift down
-
- ; Note: We want the Boolean in the high byte, so use Move.b. The 68000
- ; pushes an extra, unused byte on the stack for us.
-
- Move.b D0,-(SP)
- Move.l TextHReg,-(SP) ; Identify Text
- _TEClick ; TEClick
- Bra NextEvent ; Go get next event
-
- Drag
-
- ; The click was in the drag bar of the window. Draggit.
-
- ; DragWindow (theWindow:WindowPtr; startPt: Point; boundsRect: Rect);
- Move.l WWindow,-(SP) ; Pass window pointer
- Move.l Point,-(SP) ; mouse coordinates
- Pea WBounds ; and boundaries
- _DragWindow ; Drag Window
- Bra NextEvent ; Go get next event
-
- InMenu
-
- ; The click was in the menu bar. Determine which menu was selected, then
- ; call the appropriate routine.
-
- ; Function MenuSelect (startPt:Point) : LongInt;
- Clr.l -(SP) ; Get Space For Menu Choice
- Move.l Point,-(SP) ; Mouse At Time Of Event
- _MenuSelect ; Menu Select
- Move (SP)+,MenuReg ; Save Menu
- Move (SP)+,MenuItemReg ; and Menu Item
-
- ; On entry to Choices, the resource ID of the Menu is saved in the low
- ; word of a register, and the resource ID of the MenuItem in another.
- ; The routine MenuKey, used when a command key is pressed, returns the same
- ; info.
-
- Choices ; Called by command key too
-
- Cmp #AppleMenu,MenuReg ; Is It In Apple Menu?
- Beq InAppleMenu ; Go do Apple Menu
- Cmp #FileMenu,MenuReg ; Is It In File Menu?
- Beq InFileMenu ; Go do File Menu
- Cmp #EditMenu,MenuReg ; Is It In Edit Menu?
- Beq InEditMenu ; Go do Edit Menu
- Cmp #FontMenu,MenuReg ; Is It In Font Menu?
- Beq InFontMenu ; Go do Font Menu
-
- ChoiceReturn
-
- Bsr UnHiliteMenu ; Unhighlight the menu bar
- Bra NextEvent ; Go get next event
-
- InFileMenu
-
- ; If it was in the File menu, just check for Quit since that's all there is.
-
- Cmp #QuitItem,MenuItemReg ; Is It Quit?
- Bne ChoiceReturn ; No, Go get next event
- Bsr UnHiliteMenu ; Unhighlight the menu bar
- Move #-1,D0 ; say it was Quit
- Rts
-
- InEditMenu
-
- ; First, call SystemEdit. If a desk accessory is active that uses the Edit
- ; menu (such as the Notepad) this lets it use our menu.
- ; Decide whether it was cut, copy, paste, or clear. Ignore Undo since we
- ; didn't implement it.
-
- Bsr SystemEdit ; Desk accessory active?
- Bne ChoiceReturn ; Yes, SystemEdit handled it
- Cmp #CutItem,MenuItemReg ; Is It Cut?
- Beq Cut ; Yes, go handle it
- Cmp #CopyItem,MenuItemReg ; Is it Copy?
- Beq Copy ; Yes, go handle it
- Cmp #PasteItem,MenuItemReg ; Is it Paste?
- Beq Paste ; Yes, go handle it
- Cmp #ClearItem,MenuItemReg ; Is it Clear?
- Beq ClearIt ; Yes, go handle it
- Bra ChoiceReturn ; Go get next event
-
- InFontMenu
-
- ; If it was in the Font menu, just check for Dialog since that's all there is.
-
- Cmp #DialogItem,MenuItemReg ; Is It Dialog?
- Bne ChoiceReturn ; No, Go get next event
-
- ; Procedure TEDeActivate (hTE: TEHandle)
- Move.l TextHReg,-(SP) ; Identify Text
- _TEDeActivate ; Deactivate Text
-
- ; Obtain the current Font number, size and attributes to setup the dialog box.
- Movea.l TextHReg,A0 ; Handle to the TE record
- Movea.l (A0),A0 ; Pointer to the TE record
- Move.w teFont(A0),D0 ;- Font Number
- Cmp.w #1,D0 ; Default number?
- Bne.s @0 ; No, -> @0
- Move.w ApFontID,D0 ; Yes, load default number
- @0 Move.w D0,DtxFont(A5)
- Clr.w D0 ;- Font Face
- Move.b teFace(A0),D0 ; Place the attribute bits in the
- Move.w D0,DtxFace(A5) ; low byte of DtxFace(A5).
- Move.w teSize(A0),D0 ;- Font Size
- Bne.s @1 ; Default size, No -> @1
- Move.b FMDefaultSize,D0 ; Yes, load default size
- @1 Move.w D0,DtxSize(A5)
-
- ; Function FontDialog (Var teFont: Integer; Var teFace: Style;
- ; Var teSize: Integer): Boolean
- Clr.w -(SP)
- Pea DtxFont(A5) ; Load the font's number address
- Pea DtxFace(A5) ; Load the font's face address
- Pea DtxSize(A5) ; Load the font's size address
- Jsr FontDialog
-
- ; Test to see if the okButton was pressed (ie install the new Font variables).
- ; If the cancelButton was pressed leave the Font variables as they are.
- Move.b (SP)+,D0
- Beq.s @2
-
- ; Update the Font number, size, and face fields in the textedit record. The
- ; teAscent and teLineHite fields also require up dating. Reset the port to
- ; the textedit window, since the current GraphPort has been changed by
- ; the FontDialog routine.
-
- ; Procedure SetPort (gp: GraphPort)
- Move.l WindowPReg,-(SP)
- _SetPort
-
- ; Procedure TextFont (font: Integer)
- Move.w DtxFont(A5),-(SP)
- _TextFont
-
- ; Procedure TextFace (face: Style)
- Move.w DtxFace(A5),-(SP)
- _TextFace
-
- ; Procedure TextSize (size: Integer)
- Move.w DtxSize(A5),-(SP)
- _TextSize
-
- ; Procedure GetFontInfo (Var Info: FontInfo)
- Pea Info(A5)
- _GetFontInfo
-
- Movea.l TextHReg,A1 ; DeReference the Handle
- Movea.l (A1),A1
- Move.w DtxFont(A5),teFont(A1) ; teFont
- Move.b DtxFace+1(A5),teFace(A1) ; teFace
- Move.w DtxSize(A5),teSize(A1) ; teSize
- Move.w Info+ascent(A5),teAscent(A1) ; teAscent
- Move.w Info+ascent(A5),D0 ; teLineHite
- Add.w Info+descent(A5),D0
- Add.w Info+leading(A5),D0
- Move.w D0,teLineHite(A1)
-
- @2 Bra GoSetOurPort
-
- InAppleMenu
-
- ; It was in the Apple menu. If it wasn't About, then it must have been a
- ; desk accessory. If so, open the desk accessory.
-
- Cmp #AboutItem,MenuItemReg ; Is It About?
- Beq About ; If So Goto About...
-
- ; Procedure GetItem (menu: MenuHandle; item: Integer;
- ; Var itemString: Str255);
- Move.l AppleHReg,-(SP) ; Look in Apple Menu
- Move MenuItemReg,-(SP) ; What Item Number?
- Pea DeskName ; Get Item Name
- _GetItem ; Get Item
-
- ; Function OpenDeskAcc (theAcc: Str255) : Integer;
- Clr -(SP) ; Space For Opening Result
- Pea DeskName ; Open Desk Acc
- _OpenDeskAcc ; Open It
- Move (SP)+,D0 ; Pop result
-
- GoSetOurPort
-
- Bsr SetOurPort ; Set port to us
- Bra ChoiceReturn ; Unhilite menu and return
-
- ;--------------------------- Text Editing Routines ------------------------
-
- Cut ; CUT
-
- ; Procedure TECut (hTE: TEHandle);
- Move.l TextHReg,-(SP) ; Identify Text
- _TECut ; Cut it and copy it
- Bra ChoiceReturn ; Go get next event
-
- Copy ; COPY
-
- ; Procedure TECopy (hTE: TEHandle);
- Move.l TextHReg,-(SP) ; Identify Text
- _TECopy ; Copy text to clipboard
- Bra ChoiceReturn ; Go get next event
-
- Paste ; PASTE
-
- ; Procedure TEPaste (hTE: TEHandle);
- Move.l TextHReg,-(SP) ; Identify Text
- _TEPaste ; Paste
- Bra ChoiceReturn ; Go get next event
-
- ClearIt ;CLEAR
-
- ; Procedure TEDelete (hTE: TEHandle);
- Move.l TextHReg,-(SP) ; Point to text
- _TEDelete ; Clear without copying
- Bra ChoiceReturn ; Go get next event
-
- ; SystemEdit does undo, cut, copy, paste, and clear for desk accessories.
- ; It returns False (Beq) if the active window doesn't belong to a
- ; desk accessory.
-
- SystemEdit
-
- ; Function SystemEdit (editCmd:Integer): Boolean;
- Clr -(SP) ; Space for result
- Move MenuItemReg,-(SP) ; Get item in Edit menu
- Subq #1,(SP) ; SystemEdit is off by 1
- _SysEdit ; Do It
- Move.b (SP)+,D0 ; Pop result
- Rts ; Beq if NOT handled
-
- UnhiliteMenu
-
- ; Procedure HiLiteMenu (menuID: Integer);
- Clr -(SP) ; All Menus
- _HiLiteMenu ; UnHilite Them All
- Rts
-
-
- ;---------------------------------Misc Routines---------------------------
-
- About
-
- ; Call GetNewDialog to read the dialog box parameters from the resource file
- ; and display the box. Set the port to the box, then wait for the proper
- ; click or keypress. Finally, close the dialog box and set the pointer to us.
-
- ; Function GetNewDialog (dialogID: Integer; dStorage: Ptr;
- ; behind: WindowPtr) : DialogPtr
- Clr.l -(SP) ; Space For dialog pointer
- Move #AboutDialog,-(SP) ; Identify dialog rsrc #
- Pea DStorage ; Storage area
- Move.l #-1,-(SP) ; Dialog goes on top
- _GetNewDialog ; Display dialog box
- Move.l (SP),-(SP) ; Copy handle for Close
-
- ; Procedure SetPort (gp: GrafPort) ; Handle already on stack
- _SetPort ; Make dialog box the port
-
- ; Procedure TEDeActivate (hTE: TEHandle)
- Move.l TextHReg,-(SP) ; Identify Text
- _TEDeActivate ; Deactivate Text
-
- WaitOK
-
- ; Procedure ModalDialog (filterProc: ProcPtr;
- ; Var itemHit: Integer);
- Clr.l -(SP) ; Clear space For handle
- Pea ItemHit ; Storage for item hit
- _ModalDialog ; Wait for a response
-
- Move ItemHit,D0 ; Look to see what was hit
- Cmp #ButtonItem,D0 ; was it OK?
- Bne WaitOK ; No, wait for OK
-
- ; Procedure CloseDialog (theDialog: DialogPtr);
- _CloseDialog ; Handle already on stack
- Bra GoSetOurPort ; Set port to us and return
-
- ; ---------------------------- Data Starts Here -------------------------
-
- EventRecord ; NextEvent's Record
- What: Dc 0 ; Event number
- Message: Dc.l 0 ; Additional information
- When: Dc.l 0 ; Time event was posted
- Point: Dc.l 0 ; Mouse coordinates
- Modify: Dc 0 ; State of keys and button
- WWindow: Dc.l 0 ; Find Window's Result
-
- DStorage Dcb.w DWindLen,0 ; Storage For Dialog
- DeskName Dcb.w 16,0 ; Desk Accessory's Name
- WBounds Dc 28,4,308,508 ; Drag Window's Bounds
- ViewRect Dc 5,4,245,405 ; Text Record's View Rect
- DestRect Dc 5,4,245,405 ; Text Record's Dest Rect
- ItemHit Dc 0 ; Item clicked in dialog
-
- ;------------------------- Nonrelocatable Storage -----------------------
-
- ; Variables declared using Ds are placed in a global space relative to
- ; A5. When these variables are referenced, A5 must be explicitly mentioned.
-
- DtxFont Ds.w 1
- DtxFace Ds.w 1
- DtxSize Ds.w 1
- Info Ds.w 4 ; FontInfo Record
- WindowStorage Ds.w WindowSize ; Storage for Window
-
- End
-